%%%-------------------------------------------------------------------
%%% File:      erlymate_compile.erl
%%% @author    Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
%%% @copyright 2007 Roberto Saccon
%%% @doc  
%%% background Erlang compiling
%%% @end  
%%%
%%% The MIT License
%%%
%%% Copyright (c) 2007 Roberto Saccon
%%%
%%% Permission is hereby granted, free of charge, to any person obtaining a copy
%%% of this software and associated documentation files (the "Software"), to deal
%%% in the Software without restriction, including without limitation the rights
%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
%%% copies of the Software, and to permit persons to whom the Software is
%%% furnished to do so, subject to the following conditions:
%%%
%%% The above copyright notice and this permission notice shall be included in
%%% all copies or substantial portions of the Software.
%%%
%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
%%% THE SOFTWARE.
%%%
%%% @since 2007-12-05 by Roberto Saccon
%%%-------------------------------------------------------------------
-module(erlymate_compile).
-author('rsaccon@gmail.com').

%% API
-export([ok/0, run/4]).

%%====================================================================
%% API
%%====================================================================
%%--------------------------------------------------------------------
%% @spec 
%% @doc
%% @end 
%%--------------------------------------------------------------------
ok() -> ok.


%%--------------------------------------------------------------------
%% @spec  
%% @doc
%% @end 
%%--------------------------------------------------------------------
run(Socket, FilePath, Mode, CurrentWord) ->
    erlymate:fwrite(Socket, "~p~n", [{FilePath, Mode, CurrentWord}]),
    {exit, 0}.
      
      

%%====================================================================
%% Internal functions
%%====================================================================



%% main([]) ->
%%     File = os:getenv("TM_FILEPATH"),
%%     Dir = os:getenv("TM_DIRECTORY"),
%% run(Socket, File, Dir) ->
%%     Tokens = filename:split(Dir),
%%     Opts=[return_errors, return_warnings],
%%     crawl(hd(lists:reverse(Tokens)), Tokens, File, Opts),
%%     {exit, 0}.
%% 
%% crawl("src", _Tokens, _File, _Opts) ->
%%     io:format("not implemented yet ...");
%% crawl(_, _Tokens, File, Opts) ->
%%     main(File, File, Opts).
%% 
%% 
%% main(DisplayPath, File, Opts) ->
%%     case compile:file(File, Opts) of
%%         {ok, _Mod, []} ->
%%             io:format("<script>window.close()</script>");
%%         {ok, Mod, Warnings} ->
%%             io:format("Compilation success: ~p<script>window.close()</script><br>",[Mod]),
%%             report_warnings(Warnings);
%%         {error, Errors, Warnings} ->
%%             io:format("<b>Errors:</b><br><br>"),
%%             [list_errors(DisplayPath,F,E) || {F, E} <- Errors],
%%             report_warnings(Warnings)
%%     end.
%% 
%% 
%% list_errors(R, F, [{Line,Mod,E}|Tail]) ->
%%     io:format("<a style=\"color:red\" href=\"txmt://open/?url=file://~s&line=~p\">~s:~p: ~s</a><br>", [R, Line, F, Line, Mod:format_error(E)]),
%%     list_errors(F, F, Tail);
%% list_errors(_, _, []) -> ok.
%% 
%% 
%% report_warnings([]) ->
%%     ok;
%% report_warnings(_Warnings) ->
%%     io:format("<b>Warning:</b><br><br>display of warnings not implemented yet ...").
